输入星期几,x属于[1-7],x为1到5,输出x是工作日,否则输出x是周末。分别用if和swith实现
来源:百度知道 编辑:UC知道 时间:2024/05/27 07:25:52
#include<iostream>
using namespace std;
int main()
{
int x;
cin>>x;
if(x>0&&x<6)
cout<<"工作日";
else
cout<<"周末";
return 0;
}
#include<iostream>
using namespace std;
int main()
{
int x,a;
cin>>x;
if(x>0&&x<6)
a=1;
else
a=2;
switch(a)
{
case 1:cout<<"工作日";
break;
case 2:cout<<"周末";
break;
}
return 0;
}
调试通过
// 片段如下
int nD;
scanf("%d",nD);
if (nD>=1 && nD<=7) {
if (nD<=5) printf("工作日\n");
else printf("周末\n");
switch (nD<=5) {
case 1: printf("工作日\n"); break;
&